using System;
using System.Windows.Controls;

namespace FluentSilverlight.Expressions.Panels
{
    public class StackPanelExpression<TModel> : PanelExpression<StackPanelExpression<TModel>, TModel, StackPanel>
        where TModel : class 
    {
        private Orientation orientation = System.Windows.Controls.Orientation.Vertical;

        public StackPanelExpression() : this(string.Format("StackPanel_{0}", Guid.NewGuid()))
        {
        }

        public StackPanelExpression(string name) : base(name)
        {
        }

        public OrientationExpression<StackPanelExpression<TModel>> Orientation
        {
            get
            {
                return new OrientationExpression<StackPanelExpression<TModel>>(this, o => orientation = o);
            }
        }

        protected override void BuildUp(StackPanel element)
        {
            base.BuildUp(element);

            element.Orientation = orientation;
        }

        public static implicit operator StackPanel(StackPanelExpression<TModel> expression)
        {
            var stackPanel = new StackPanel();
            expression.BuildUp(stackPanel);

            return stackPanel;
        }

        protected override StackPanelExpression<TModel> thisInstance()
        {
            return this;
        }
    }
}